//打印方法
import { message, Modal } from "antd";
import { formatAmount } from "@/utils/utils.jsx";
import { queryDouYinPrintParam } from "@/services/common";

//特殊账号唯一码打印（fzbxqj和fzbzr）
export function printLodopUnicode(list, uuid, callback) {
	try {
		LODOP = getLodop();
		let x = parseInt(list.length / 10),
			y = list.length % 10; //10个一组
		let z = x;
		if (y > 0) {
			//有余数需要多打一轮
			z = x + 1;
		}
		for (let i = 1; i <= z; i++) {
			LODOP.PRINT_INIT("唯一码打印");
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", list[0].printer); //为每个打印单独设置任务名
			if (uuid == fzbxqjUuid || uuid == 693731) {
				//fzbxqj
				LODOP.SET_PRINT_PAGESIZE(1, 500, 300, "");
			} else {
				//fzbzr
				LODOP.SET_PRINT_PAGESIZE(1, 600, 400, "");
			}
			let num = 10; //批次打印数量
			if (i > x) {
				//最后一批的时候 需要改变最后一次打印的数量
				num = y;
			}
			for (let j = 1; j <= num; j++) {
				let order = (i - 1) * 10 + j - 1; //当前在数组的哪一位
				if (uuid == fzbxqjUuid) {
					//fzbxqj
					CreateOnePage1(list[order]);
				} else if (uuid == 661928) {
					//fzbzr
					CreateOnePage2(list[order]);
				} else if (uuid == 692730) {
					//吴书荣
					CreateOnePage3(list[order]);
				} else {
					CreateOnePage4(list[order]);
				}
			}
			LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME", "唯一码打印" + i); //为每个打印单独设置任务名
			// LODOP.PRINT_DESIGN()
			LODOP.PRINT();
			// LODOP.PREVIEW()
		}

		LODOP.On_Return = function () {
			callback &&
				callback({
					success: true,
					status: 1
				});
		};
	} catch (error) {
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
}

//打印电子面单
export function print(type, message, callback) {
	if (type == 1) {
		let socket = new WebSocket("ws://127.0.0.1:5000");
		console.log(type, message, 'callnack')
		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "拼多多打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				const data = JSON.parse(event.data);
				if (data.cmd == "PrintResultNotify") {
					if (data.taskStatus == "printed") {
						callback({ ...data, status: "success" });
						socket.close();
					} else if (data.taskStatus == "failed") {
						callback(data);
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 6) {
		let socket = new WebSocket("ws://localhost:9113");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "京东打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.success == "true") {
					callback({ ...data, status: "success" });
					socket.close();
				} else if (data.success == "false") {
					callback({ ...data, status: false });
					socket.close();
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 8) {
		let socket = new WebSocket("ws://127.0.0.1:12233/print");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "唯品会打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.result == "success") {
					callback({ ...data, status: "success" });
					socket.close();
				} else {
					callback({ ...data, status: false });
					socket.close();
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 14) {
		let socket = new WebSocket("ws://127.0.0.1:16888/ks/printer");
		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "快手打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				console.log("onmessage event", event);
				var data = JSON.parse(event.data);
				if (data.status == "success") {
					callback(data);
					socket.close();
				} else if (data.status == "wrong" || data.cmd == "notifyPrintResult") {
					callback({ ...data, status: false });
					socket.close();
				} else if (data.status == "failed") {
					callback({ ...data, status: false });
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 15) {
		let socket = new WebSocket("ws://127.0.0.1:13888");
		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "抖音打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.cmd == "notifyPrintResult") {
					if (data.taskStatus == "printed") {
						callback({ ...data, status: "success" });
						socket.close();
					} else if (data.taskStatus == "failed") {
						callback({ ...data, status: undefined }); //重置status:'faild'为假值
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 25) {
		let socket = new WebSocket("ws://127.0.0.1:12705");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "微信视频号打印组件出错了，请检查"
			});
		};

		socket.onopen = function () {
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.command === "print") {
					if (data.results?.[0]?.success) {
						callback({ ...data, status: "success" });
						socket.close();
					} else {
						callback({ ...data, status: false });
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 33) {
		let socket = new WebSocket("ws://127.0.0.1:23825");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "得物打印组件出错了，请检查"
			});
		};

		socket.onopen = function () {
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.cmd === "print") {
					if (data.status == "success") {
						callback({ ...data, status: "success" });
						socket.close();
					} else {
						callback({ ...data, status: false });
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else if (type == 40) {
		let socket = new WebSocket("ws://127.0.0.1:14528");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "小红书打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.cmd == "notifyPrintResult") {
					if (data.taskStatus == "printed") {
						callback({ ...data, status: "success" });
						socket.close();
					} else if (data.taskStatus == "failed") {
						callback({ ...data, message: data.msg });
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	} else {
		let socket = new WebSocket("ws://127.0.0.1:13528");

		// Socket失败
		socket.onerror = function (event) {
			callback({
				status: false,
				message: "菜鸟打印组件出错了，请检查"
			});
		};

		// 打开Socket
		socket.onopen = function (event) {
			// 监听消息
			socket.onmessage = function (event) {
				var data = JSON.parse(event.data);
				if (data.cmd == "notifyPrintResult") {
					if (data.taskStatus == "printed") {
						callback({ ...data, status: "success" });
						socket.close();
					} else if (data.taskStatus == "failed") {
						callback({ ...data, message: data.msg });
						socket.close();
					}
				}
			};
			socket.send(JSON.stringify(message));
		};
	}
}

//平台映射
const platfromMap = {
	1: "菜鸟",
	2: "拼多多",
	6: "京东",
	8: "唯品会",
	14: "快手",
	15: "抖音",
	25: "微信视频号",
	33: "得物",
	40: "小红书"
};

//打印组件映射
const componentsMap = {
	菜鸟: "ws://127.0.0.1:13528",
	拼多多: "ws://127.0.0.1:5000",
	京东: "ws://127.0.0.1:9113",
	唯品会: "ws://127.0.0.1:12233/print",
	快手: "ws://127.0.0.1:16888/ks/printer",
	抖音: "ws://127.0.0.1:13888",
	微信视频号: "ws://127.0.0.1:12705",
	得物: "ws://127.0.0.1:23825",
	小红书: "ws://127.0.0.1:14528"
};

/**
 * @desc：校验打印组件是否开启
 * @arr: Array:打印订单对应的平台(参数为undefined时 校验所有打印组件 包括lodop)
 * @callback: Function:回调函数
 */

export const checkComponentsIsOpen = (arr = [1, 2, 6, 7, 8, 14, 15, 25, 33, 40], callback, tips = true) => {
	const promises = [],
		errArr = [];
	arr.map(item => {
		if (item != 7) {
			promises.push(
				new Promise(function (resolve, reject) {
					var websocket = new WebSocket(componentsMap[platfromMap[item]]);
					websocket.onopen = function () {
						resolve(platfromMap[item]);
					};
					websocket.onerror = function () {
						reject(platfromMap[item]);
					};
				})
			);
		}
	});

	Promise.allSettled(promises)
		.then(results => {
			results.map(item => {
				if (item.status == "rejected") {
					errArr.push(item.reason);
				}
			});
			if (arr.includes(7)) {
				try {
					LODOP;
				} catch {
					errArr.push("Lodop");
				}
			}
			if (errArr.length) {
				tips &&
					Modal.info({
						content: (
							<div>
								检测到您未开启<span style={{ fontWeight: "bold", wordBreak: "break-all" }}>【{errArr.join("，")}】</span>
								打印组件，为不影响相关订单打印功能，请先及时开启（打印组件可去ERP首页进行下载）
							</div>
						),
						onOk() {
							callback && callback({ modalOK: true });
						}
					});
				callback && callback({ status: false, errArr });
			} else {
				callback && callback({ status: true });
			}
		})
		.catch(err => console.log(err, "err"));
};

/**
 * @desc:获取所有的打印机
 * @callback: Function:回调函数
 * @isTips: boolean:表示是否需要提示（未获取到打印机）页面初始化等不需要提示
 */

export const getAllPrinter = (callback, isTips = true) => {
	//isTips boolean
	let printerArr = [];
	try {
		printerArr = LODOP.Printers.list.map(item => item.name); //lodop获取速度明显较快
		callback && callback(printerArr);
		if (!printerArr.length && isTips) {
			Modal.info({
				content: "LODDP已开启，但未检测到可用的打印机"
			});
		}
	} catch {
		const promises = [];
		Object.keys(platfromMap).map(item => {
			if (item == 8) return; //唯品会response非预期
			promises.push(
				new Promise(function (resolve, reject) {
					var websocket = new WebSocket(componentsMap[platfromMap[item]]);
					websocket.onopen = function (evt) {
						// 监听消息
						websocket.onmessage = function (event) {
							const data = JSON.parse(event.data);
							if (data.cmd == "getPrinters") {
								resolve(data.printers.map(item => item.name));
							} else {
								resolve(data?.detailinfo?.printers || []);
							}
						};

						if (item == 6) {
							websocket.send(JSON.stringify({ orderType: "GET_Printers" }));
						} else {
							websocket.send(JSON.stringify({ cmd: "getPrinters" }));
						}
					};
					websocket.onerror = function (evt) {
						reject(platfromMap[item]);
					};
				})
			);
		});

		Promise.allSettled(promises)
			.then(results => {
				results.map(item => {
					if (item.value) {
						printerArr = [...new Set(printerArr.concat(item.value))];
					}
				});
				callback && callback(printerArr);
				if (!printerArr.length && isTips) {
					Modal.info({
						content: "未检测到打印机，请打开打印组件后重试"
					});
				}
			})
			.catch(err => console.log(err, "err"));
	}
};

/**
 * @desc:判断勾选订单所属平台
 * @param {*} list :订单数组对象
 * @returns
 */
export const judgeHasWhichPlatform = list => {
	if (list && list.length) {
		const mapArr = {
			1: 1, //淘宝
			2: 2, //拼多多
			// 3: 6,//京东（可能不存在）
			// 4: 6,//京东无界（可能不存在）
			5: 1, //顺丰
			6: 6, //京东物流云
			7: 7, //唯品会jitx
			8: 8, //唯品会
			14: 14, //快手
			15: 15, //抖店
			25: 25, //微信视频号
			26: 1, //淘宝易发货
			28: 2, //拼多多
			29: 6, //京东
			32: 7, //得物lodop
			33: 33, //得物
			40: 40 //小红书
		};
		const arr = list.map(item => (mapArr[item.platform] ? mapArr[item.platform] : 1)); //默认值走菜鸟
		return [...new Set(arr)];
	}
};

//打印机列表
export const getPrinterList = (type = 1, callback) => {
	// 打开Socket
	var socket = new WebSocket(componentsMap[platfromMap[type]]);
	socket.onopen = function () {
		if (type == 6) {
			socket.send(JSON.stringify({ orderType: "GET_Printers" }));
		} else if (type == 25) {
			socket.send(
				JSON.stringify({
					requestID: String(Date.now()),
					command: "getPrinterList"
				})
			);
		} else {
			socket.send(
				JSON.stringify({
					cmd: "getPrinters",
					requestID: Date.now(),
					version: "1.0"
				})
			);
		}
	};

	// 监听消息
	socket.onmessage = function (event) {
		const data = JSON.parse(event.data);
		if (["connect"].includes(data.cmd)) {
			return;
		}
		if (data.cmd == "getPrinters") {
			callback && callback(data.printers.map(item => item.name));
		} else if (data.command == "getPrinterList") {
			callback && callback(data.printerList.map(item => item.name));
		} else {
			callback && callback(data.detailinfo.printers);
		}
	};
};

//预览前校验下组件状态
export const singleCheckComponent = (type, callback) => {
	const checkPromise = new Promise((resolve, reject) => {
		var websocket = new WebSocket(componentsMap[platfromMap[type]]);
		websocket.onopen = function (evt) {
			resolve(platfromMap[type]);
		};
		websocket.onerror = function (evt) {
			reject(platfromMap[type]);
		};
	});
	checkPromise
		.then(res => {
			getPrinterList(type, printers => {
				// console.log(printers)
				if (printers && printers.length) {
					callback && callback({ printers, status: 2 });
				} else {
					callback && callback({ status: 1 });
				}
			});
		})
		.catch(err => {
			Modal.info({
				content: (
					<div>
						检测到您未开启<span style={{ fontWeight: "bold" }}>【{err}】</span>
						打印组件，请先及时开启（打印组件可去ERP首页进行下载）
					</div>
				)
			});
			callback && callback({ status: 3 });
		});
};

//打印预览（数据发给打印组件）
export const printCode = (type, message, callback) => {
	var socket = new WebSocket(componentsMap[platfromMap[type]]);
	// 打开Socket
	socket.onopen = function () {
		// 监听消息
		socket.onmessage = function (event) {
			const data = JSON.parse(event.data);
			if (
				data.previewImage?.length ||
				data?.detailinfo?.imgurl ||
				data?.detailinfo?.imgdata ||
				data.previewURL ||
				data.previewUrl
			) {
				//后者兼容京东
				callback && callback(data);
			}
			// else{
			// 	Modal.info({
			// 		content:"预览回调失败"
			// 	})
			// }
		};
		socket.send(JSON.stringify(message));
	};

	// Socket失败
	socket.onerror = function () {
		callback &&
			callback({
				status: false,
				message: `${platfromMap[type]}打印组件出错了`
			});
	};
};

// platform 订单类型  拼多多 或 淘宝
// orderSn 订单号
// printData 打印数据
// num 当前页序号
// length 总共打印张数
// name 打印机名称
//customData 自定义区域
export function previewOrder(list, callback) {
	const { platform, orderSn, printData, num = 0, length = 1, name, customData } = list;

	if (platform == 0) {
		//清单
		printCheckList(JSON.parse(printData), callback);
	} else if (platform == 2 || platform == 28) {
		//拼多多
		const data = {
			ERPId: 303379400,
			cmd: "print",
			requestID: orderSn + Date.now(),
			task: {
				documents: [
					{
						contents: [JSON.parse(printData), { ...customData }],
						documentID: orderSn
					}
				],
				notifyType: ["print"],
				preview: true,
				previewType: "image",
				printer: name,
				taskID: orderSn + Date.now()
			},
			version: "1.0"
		};
		printCode(2, data, callback);
	} else if (platform == 6) {
		//京东
		const printObj = JSON.parse(printData);
		const data = {
			orderType: "PRE_View",
			// dataType: "app",
			parameters: {
				printName: name,
				addData: printObj.addData,
				tempUrl: printObj.templateURL,
				customTempUrl: customData.templateURL,
				customData: [customData.data],
				printData: [printObj.data]
			}
		};
		printCode(6, data, callback);
	} else if (platform == 7) {
		//唯品会
		printVipShop(printData, callback, name);
	} else if (platform == 14) {
		//快手
		const printObj = JSON.parse(printData);
		const data = {
			cmd: "print",
			requestID: orderSn + Date.now(),
			version: "1.0",
			task: {
				taskID: orderSn + Date.now(),
				preview: true,
				printer: name,
				previewType: "png",
				firstDocumentNumber: num + 1,
				totalDocumentCount: length,
				documents: [
					{
						documentID: orderSn,
						contents: [
							{
								addData: printObj.addData,
								encryptedData: printObj.printData,
								signature: printObj.signature,
								key: printObj.key,
								templateURL: printObj.templateURL,
								ver: "waybill_print_secret_version_1"
							},
							{
								customData: customData?.data,
								templateURL: customData?.templateURL
							}
						]
					}
				]
			}
		};
		print(14, data, callback);
	} else if (platform == 15) {
		//抖音
		const { templateURL, print_data } = JSON.parse(printData);
		const newData = {
			templateURL,
			data: print_data
		};
		const data = {
			cmd: "print",
			requestID: orderSn + Date.now(),
			version: "1.0",
			task: {
				taskID: orderSn + Date.now(),
				preview: true,
				printer: name,
				previewType: "png",
				documents: [
					{
						documentID: orderSn,
						contents: [newData, { ...customData }]
					}
				]
			}
		};
		printCode(15, data, callback);
	} else if (platform == 25) {
		const printObj = JSON.parse(printData);
		const data = {
			command: "preview",
			version: "2.0",
			requestID: orderSn + Date.now(),
			printer: name,
			taskList: [
				{
					taskID: orderSn + Date.now(),
					printInfo: printObj.printData,
					printNum: {
						curNum: num + 1,
						sumNum: length
					},
					customInfo: { templateUrl: customData?.templateURL, data: customData?.data },
					extendData: { ...printObj.addData }
				}
			]
		};
		printCode(25, data, callback);
	} else if (platform == 33) {
		//得物
		const printObj = JSON.parse(printData);
		const data = {
			cmd: "preview",
			version: "2.2.1",
			requestID: orderSn + Date.now(),
			task: {
				isvName: "isvName", // ISV 名称
				taskID: orderSn + Date.now(),
				printer: name,
				firstDocumentNumber: 1,
				totalDocumentCount: 1,
				documents: [
					{
						printData: { ...printObj.printData, customContent: undefined },
						customContent: printObj.customContent
					}
				]
			}
		};
		printCode(33, data, callback);
	} else if (platform == 40) {
		//小红书
		const data = {
			cmd: "print",
			requestID: orderSn + Date.now(),
			version: "1.0",
			task: {
				taskID: orderSn + Date.now(),
				preview: true,
				printer: name,
				previewType: "pdf",
				firstDocumentNumber: 1,
				totalDocumentCount: 1,
				documents: [
					{
						documentID: orderSn,
						contents: [JSON.parse(printData), { ...customData }]
					}
				]
			}
		};
		printCode(40, data, callback);
	} else {
		let data;
		if (platform == 5) {
			//顺丰
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: true,
					printer: name,
					previewType: "image",
					firstDocumentNumber: num + 1,
					totalDocumentCount: length,
					documents: [
						{
							documentID: orderSn,
							contents: [JSON.parse(printData)]
						}
					]
				}
			};
		} else {
			//淘宝
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: true,
					printer: name,
					previewType: "image",
					firstDocumentNumber: num + 1,
					totalDocumentCount: length,
					documents: [
						{
							documentID: orderSn,
							contents: [JSON.parse(printData), { ...customData }]
						}
					]
				}
			};
		}
		printCode(1, data, callback);
	}
}

// 打印商品条码
export function printGoods(data, callback) {
	try {
		const {
			platType,
			qmChannel,
			waveType,
			waveName,
			goodsNum,
			goodsName = "",
			goodsUniqueCode,
			orderSn,
			goodsCode,
			goodsSpce,
			platform,
			ecSpuId,
			ecSkuId,
			payTime,
			pickLabel,
			index,
			isStoragePage,
			ecStoreName,
			address,
			basketName
		} = data;
		// console.log(data,payTime,'payTime')
		const customType = waveType == 0 ? "单" : "多";
		const customNum = "[" + goodsNum + "]件";

		LODOP = getLodop();
		LODOP.PRINT_INIT("打印商品条码");
		if (index || index == 0) {
			// console.log('index',index)
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}
		if (qmChannel == 5 || qmChannel == 16) {
			LODOP.SET_PRINT_PAGESIZE(0, 750, 530, "");
			LODOP.ADD_PRINT_TEXT(1, 7, 195, 45, ecSpuId);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(60, 6, 195, 34, goodsSpce);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(9, 205, 79, 28, qmChannel == 5 ? "JIT" : "W");
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(39, 204, 82, 42, pickLabel);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_BARCODE(96, 13, 196, 54, "Code39", ecSkuId);
			if (qmChannel == 16) {
				LODOP.ADD_PRINT_TEXT(166, 19, 180, 18, `打印日期：${new Date().toLocaleDateString().replaceAll("/", "-")}`);
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			}
			LODOP.ADD_PRINT_BARCODE(105, 190, 94, 80, "QRCode", goodsUniqueCode);
			LODOP.ADD_PRINT_TEXT(175, 180, 162, 20, goodsUniqueCode);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
		} else if (platType) {
			//聚水潭订单
			const tableHtml = `<style>*{box-sizing:border-box;}
			.textOverflowMultiThree {	height: 54px;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 4;overflow: hidden;}</style>
			<div style="width:100%;display:flex;justify-content:center;align-items:center;">
				<div style="width:90%;border:1px solid #ccc;display:flex;flex-wrap:wrap;font-size:12px;">
					<span style="width:50%;border-right:1px solid #ccc;">款式</span>
					<span style="width:50%;">颜色</span>
					<span style="width:50%;border-top:1px solid #ccc;border-right:1px solid #ccc;" class="textOverflowMultiThree">${ecSpuId}</span>
					<span style="width:50%;border-top:1px solid #ccc;" class="textOverflowMultiThree">${goodsSpce}</span>
			  </div>
			</div>`;
			LODOP.SET_PRINT_PAGESIZE(0, 720, 530, "");
			LODOP.ADD_PRINT_BARCODE(4, 47, 220, 50, "128Auto", orderSn);
			LODOP.ADD_PRINT_TEXT(18, 219, 101, 33, platform);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 16);
			LODOP.ADD_PRINT_HTM(56, -10, 302, 116, tableHtml);
			LODOP.ADD_PRINT_TEXT(142, 5, 215, 21, ecSkuId);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
			LODOP.ADD_PRINT_TEXT(130, 0, 188, 16, `付款时间:${payTime}`);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
			LODOP.ADD_PRINT_TEXT(130, 170, 133, 15, `打印日期:${new Date().toLocaleDateString().replace(/\//g, "-")}`);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
			LODOP.ADD_PRINT_BARCODE(160, 6, 220, 41, "128A", goodsUniqueCode);
			LODOP.ADD_PRINT_TEXT(158, 151, 40, 20, customType);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 18);
			LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
			LODOP.ADD_PRINT_TEXT(187, 157, 40, 20, customNum);
			LODOP.ADD_PRINT_BARCODE(140, 206, 82, 74, "QRCode", ecSkuId);
		} else if (isStoragePage) {
			LODOP.SET_PRINT_PAGESIZE(0, 800, 530, "");
			LODOP.ADD_PRINT_BARCODE(5, 11, 217, 46, "128Auto", goodsUniqueCode);
			LODOP.ADD_PRINT_TEXT(2, 186, 142, 35, waveName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
			LODOP.ADD_PRINT_TEXT(30, 199, 119, 23, customType);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
			LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(53, 10, 180, 19, orderSn);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(52, 171, 95, 22, customNum);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(68, 10, 312, 40, goodsName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
			LODOP.ADD_PRINT_TEXT(112, 9, 312, 20, goodsSpce);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(129, 9, 298, 19, ecStoreName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(149, 9, 298, 16, address);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(168, 9, 298, 19, goodsCode);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.ADD_PRINT_TEXT(140, 200, 200, 19, basketName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
		} else {
			let nameSpec = goodsName + goodsSpce;
			//超过2行从后往前截取
			if (nameSpec.length > 48) {
				nameSpec = nameSpec.substring(nameSpec.length - 48, nameSpec.length);
			}
			LODOP.SET_PRINT_PAGESIZE(0, 800, 330, "");
			LODOP.ADD_PRINT_BARCODE(5, 11, 217, 46, "128Auto", goodsUniqueCode);
			LODOP.ADD_PRINT_TEXT(2, 186, 142, 35, waveName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
			LODOP.ADD_PRINT_TEXT(30, 199, 119, 23, customType);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
			LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(53, 10, 135, 19, orderSn);
			LODOP.ADD_PRINT_TEXT(66, 10, 300, 40, nameSpec);
			LODOP.ADD_PRINT_TEXT(52, 171, 95, 22, customNum);
			LODOP.ADD_PRINT_TEXT(96, 10, 300, 40, goodsCode);
			LODOP.ADD_PRINT_TEXT(42, 220, 100, 22, basketName);
		}
		// LODOP.PREVIEW()
		LODOP.PRINT();
		//  LODOP.PRINT_DESIGN(); //设计+
		LODOP.On_Return = function (TaskID, value) {
			callback &&
				callback({
					success: true,
					status: 0
				});
		};
	} catch (error) {
		console.log(error, "printGoodsCode");
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
}

//打印系统商品编码
export function printGoodsCode(data) {
	const { goodsName, skuName, skuId, spuId, index } = data;
	const htmlStr1 = `<div style="height:42px;font-size:12px;line-height:14px;width:100%;overflow:hidden;padding-right:6px;">${goodsName}</div>`,
		htmlStr2 = `<div style="height:28px;font-size:12px;line-height:14px;width:100%;overflow:hidden;word-wrap: break-word;word-break:break-all;padding-right:6px;">`;
	try {
		LODOP = getLodop();
		LODOP.PRINT_INIT("打印商品条码");
		if (index || index == 0) {
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}
		LODOP.SET_PRINT_PAGESIZE(0, 700, 500, "");
		LODOP.ADD_PRINT_HTM(0, 0, 268, 42, htmlStr1);
		LODOP.ADD_PRINT_HTM(42, 0, 268, 30, `${htmlStr2}${skuName}</div>`);
		LODOP.ADD_PRINT_BARCODE(70, 2, 260, 60, "128Auto", `${skuId}`); //以：-作为标记区分，扫码打单的时候用
		LODOP.SET_PRINT_STYLEA(0, "ShowBarText", 0);
		LODOP.ADD_PRINT_TEXT(131, 0, 268, 30, `商品编码：${skuId}`);
		LODOP.SET_PRINT_STYLEA(0, "TextNeatRow", true); //允许标点溢出，且英文单词拆开。
		LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 0);
		LODOP.ADD_PRINT_TEXT(159, 0, 268, 30, `款式编码：${spuId}`);
		LODOP.SET_PRINT_STYLEA(0, "TextNeatRow", true); //允许标点溢出，且英文单词拆开。
		LODOP.SET_PRINT_STYLEA(0, "LineSpacing", 0);
		LODOP.PRINT();
		//  LODOP.PRINT_DESIGN(); //设计+
	} catch (err) {
		console.log(err);
		message.info("请开启打印组件");
	}
}
// printGoodsCode({
// 	goodsName:'2020新款60支水洗真丝全棉天丝四件套—简'.repeat(20),
// 	skuName:'颜色分类:简约-墨绿B版全棉,适用床尺寸:1.5m床单款四件套'.repeat(20),
// 	skuId:"K000008842".repeat(20),
// 	spuId:'sdfsfsdfsfsdfsdf'.repeat(20)
// })

//唯品会打印
export function printVipShop(html, callback, index) {
	if (index || index == 0) {
		LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
	}
	LODOP.PRINT_INIT("");
	LODOP.SET_PRINT_PAGESIZE(0, 1000, 1200, "");
	LODOP.ADD_PRINT_HTM(0, 0, 170, 474, html);

	LODOP = getLodop();
	// LODOP.PREVIEW(); // 预览
	//  LODOP.PRINT_DESIGN(); //设计
	LODOP.PRINT();

	LODOP.On_Return = function (TaskID, value) {
		callback &&
			callback({
				success: true,
				status: 1
			});
	};
}

//清单打印
export function printCheckList(obj = {}, callback, index) {
	const { goodsInfo = [], outOrderSn = "" } = obj;

	let code;
	if (outOrderSn.includes(",")) {
		code = outOrderSn.split(",")[0];
	} else {
		code = outOrderSn;
	}

	let goodsStr = "";
	goodsInfo.map(item => {
		goodsStr += item + "<br />";
	});

	LODOP.PRINT_INIT("");
	if (index || index == 0) {
		LODOP.SET_PRINTER_INDEX(index);
	}
	LODOP.SET_PRINT_PAGESIZE(0, 760, 1300, "");
	LODOP.ADD_PRINT_BARCODE(-11, 176, 107, 362, "128A", code);
	LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
	LODOP.SET_PRINT_STYLEA(0, "Angle", 90);
	LODOP.ADD_PRINT_HTM(
		12,
		10,
		170,
		474,
		'<p style="word-break:break-all;font-size:14px"><span style="font-weight:600;">商品名称：</span><br /><br />' +
		goodsInfo.join("<br />") +
		"</p>"
	);

	LODOP = getLodop();
	// LODOP.PREVIEW(); // 预览
	// LODOP.PRINT_DESIGN(); //设计
	LODOP.PRINT();

	LODOP.On_Return = function (TaskID, value) {
		callback &&
			callback({
				success: true,
				status: 1
			});
	};
}

// 打印退货商品码
export function printReturnGoods(data, callback, index) {
	const {
		uniqueCode,
		headCode,
		refundAccount = "",
		storeAddress = "",
		storeName,
		handleType,
		remark = "",
		logisticsCompany,
		logisticsNo,
		type,
		name = "",
		orderSn
	} = data;
	try {
		if (index || index == 0) {
			//指定打印机进行打印
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}
		// 判断是否是无头件
		if (handleType == 3 || type == 2) {
			const code = headCode || uniqueCode;
			const left = 125;
			const right = 200;
			LODOP.PRINT_INIT("");
			LODOP.SET_PRINT_PAGESIZE(0, 800, 300, "");
			LODOP.ADD_PRINT_BARCODE(7, 7, 159, 56, "128A", code);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
			LODOP.ADD_PRINT_TEXT(7, left, right, 20, "无头件退货条码");
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(24, left, right, 20, "快递名称:" + logisticsCompany);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(40, left, right, 20, "快递单号:" + logisticsNo);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(65, 7, 312, 20, "备注:" + remark);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			// LODOP.ADD_PRINT_TEXT(76, 7, 312, 20, "商品唯一码:" + uniqueCode);
			// LODOP.ADD_PRINT_TEXT(95, 7, 311, 20, "备注:" + remark);
		} else {
			const left = 145;
			LODOP.PRINT_INIT("");
			LODOP.SET_PRINT_PAGESIZE(0, 800, 300, "");
			LODOP.ADD_PRINT_BARCODE(7, 7, 159, 56, "128Auto", uniqueCode);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
			LODOP.ADD_PRINT_TEXT(7, left, 189, 20, "退货条码");
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(24, left, 189, 20, storeName);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.ADD_PRINT_TEXT(40, left, 189, 20, "退货员:" + name);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.ADD_PRINT_TEXT(65, 7, 312, 20, "订单号:" + orderSn);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.ADD_PRINT_TEXT(80, 7, 311, 20, "门店地址:" + storeAddress);
			LODOP.SET_PRINT_STYLEA(0, "FontSize", 9);
			LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			// LODOP.ADD_PRINT_TEXT(76, 7, 312, 20, "商品唯一码:" + uniqueCode);
			// LODOP.ADD_PRINT_TEXT(95, 7, 311, 20, "门店地址:" + storeAddress);
		}
		LODOP = getLodop();
		LODOP.PRINT();
		// LODOP.PREVIEW(); // 预览
		LODOP.On_Return = function (TaskID, value) {
			callback &&
				callback({
					success: true,
					status: 0
				});
		};
	} catch (error) {
		console.log(error);
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
	// LODOP.PREVIEW(); // 预览
	// LODOP.ADD_PRINT_HTM(); // 超文本
	// LODOP.PRINT_DESIGN(); //设计
}

// 打印库位编码；
export function printLocationCode(code, callback) {
	try {
		LODOP = getLodop();
		LODOP.PRINT_INIT("");
		LODOP.SET_PRINT_PAGESIZE(0, 800, 300, "");
		LODOP.ADD_PRINT_BARCODE(60, 28, 249, 50, "128B", code);
		LODOP.ADD_PRINT_TEXT(12, 16, 275, 20, "库位编码");
		LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
		LODOP.ADD_PRINT_TEXT(36, 16, 276, 20, code);
		LODOP.SET_PRINT_STYLEA(0, "FontSize", 11);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.PRINT();
		LODOP.On_Return = function (TaskID, value) {
			callback &&
				callback({
					success: true,
					status: 0
				});
		};
	} catch {
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
}

// 判断是否安装lodop
export function ynLodop() {
	let box = null;
	try {
		LODOP = getLodop();
		box = {
			success: true,
			error: "lodop准备就绪"
		};
	} catch {
		box = {
			success: false,
			error: "检测不到lodop"
		};
	}
	return box;
}

export const testLodopIsOpen = () => {
	let isOpen = true;
	try {
		LODOP = getLodop();
	} catch (err) {
		isOpen = false;
	}
	return isOpen;
};

const obj = {
	goodsName: "这是订单商品名称11111111",
	goodsSpce: "这是订单规格属性2222222",
	spuId: "这是订单款式编码3333333333",
	goodsId: "这是订单商品编码4444444444"
};

const goodsInfoMap = {
	goodsName: "订单商品名称",
	goodsSpce: "订单规格属性",
	spuId: "订单款式编码",
	goodsId: "订单商品编码"
};

//得物打印快递单号
export function printDewu({ index, logisticsNo }, callback) {
	let LODOP;
	try {
		LODOP = getLodop();
		if (index || index == 0) {
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}
		LODOP.PRINT_INIT("");
		LODOP.SET_PRINT_PAGESIZE(0, 760, 500, "");
		LODOP.ADD_PRINT_BARCODE(5, 5, 240, 72, "128Auto", logisticsNo);
		// LODOP.PRINT_DESIGN()
		LODOP.PRINT();

		LODOP.On_Return = function () {
			callback && callback({ status: true });
		};
	} catch {
		console.log("error");
	}
}

/**
 * @desc:合格证打印
 * data: 模板数据 必传
 * goods:商品数据 必传
 * type: 1 打印  2 预览
 * index: 设置打印机（打印机列表索引）
 * callback: 执行回调
 */

// LODOP.SELECT_PRINTER()
export function printCard({ type = 1, data = {}, goods = obj, index }, callback) {
	let LODOP;

	const { templateName, totalWidth, totalHeight, templateValue, list } = data;

	const commonAddStyle = item => {
		Object.keys(item).map(key => {
			if (key == "fontWeight") {
				LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
			} else if (key == "fontStyle") {
				LODOP.SET_PRINT_STYLEA(0, "Italic", 1);
			} else if (key == "textDecoration") {
				LODOP.SET_PRINT_STYLEA(0, "Underline", 1);
			} else {
				LODOP.SET_PRINT_STYLEA(0, key, item[key]);
			}
		});
		LODOP.SET_PRINT_STYLEA(0, "TextNeatRow", true); //允许标点溢出，且英文单词拆开。
	};

	try {
		LODOP = getLodop();
		if (index || index == 0) {
			// LODOP.SET_PRINTER_INDEX(index)
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}
		LODOP.PRINT_INIT(templateName);
		// LODOP.SELECT_PRINTER()
		LODOP.SET_PRINT_PAGESIZE(0, totalWidth * 10, totalHeight * 10, "");
		LODOP.PRINT_INITA("1mm", "0mm", `${totalWidth}mm`, `${totalHeight}mm`, templateName);
		// LODOP.ADD_PRINT_TABLE(0,0,totalWidth*3.8,totalHeight*3.8,'')
		// LODOP.SET_PRINT_STYLEA(0,"PageIndex",1)
		templateValue &&
			JSON.parse(templateValue).map(item => {
				const { top, left, width, height } = item;

				if (top < totalHeight * 3.8) {
					if (item.type == "text") {
						let str = "";
						if (item.props) {
							item.props.map(prop => {
								str += `${goodsInfoMap[prop]}：${goods[prop] ? goods[prop] : ""};`;
							});
						}
						if (item.prop) {
							//自定义属性
							{
								if (list && list.length > 0) {
									//自定义属性不为空
									const propItem = list.find(z => z.attributeName == item.prop);
									if (propItem) {
										str += `${item.prop}：${propItem.attributeValue};`;
									} else {
										str += `${item.prop}： ;`;
									}
								} else {
									// 为空需要带上标题
									str += `${item.prop}： ;`;
								}
							}
						}
						LODOP.ADD_PRINT_TEXT(top, left, width, height, str);
						commonAddStyle(item);
					} else if (item.type == "customtext") {
						LODOP.ADD_PRINT_TEXT(top, left, width, height, item.value);
						commonAddStyle(item);
					} else if (item.type == "barcode" && item.value) {
						if (item.value == "12345678") {
							if (goods["goodsId"]) {
								LODOP.ADD_PRINT_BARCODE(top, left, width, height, "128Auto", goods["goodsId"]);
							}
						} else {
							LODOP.ADD_PRINT_BARCODE(top, left, width, height, "128Auto", item.value);
						}
					} else if (item.type == "qrcode") {
						if (item.value == "#ecSkuId#") {
							LODOP.ADD_PRINT_BARCODE(top, left, width, height, "QRCode", goods["ecSkuId"]);
						} else if (item.value == "#goodsCode#") {
							LODOP.ADD_PRINT_BARCODE(top, left, width, height, "QRCode", goods["goodsCode"]);
						} else {
							LODOP.ADD_PRINT_BARCODE(top, left, width, height, "QRCode", item.value);
						}
						// LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",5);
						// LODOP.SET_PRINT_STYLEA(0,"QRCodeErrorLevel","L");
					} else if (item.type == "picture") {
						LODOP.ADD_PRINT_IMAGE(
							top,
							left,
							width,
							height,
							`<img border='0' src=${item.value} width=${width} height=${height} />`
						);
						// LODOP.SET_PRINT_STYLEA(0,"Horient",2);
					}
				}
			});

		// LODOP.PRINT_DESIGN()

		if (type == 1) {
			LODOP.PRINT();
		} else {
			LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page"); //按整页缩放
			// LODOP.SET_PRINT_MODE("FULL_WIDTH_FOR_OVERFLOW",true);//宽度溢出缩放
			// LODOP.SET_PRINT_MODE("FULL_HEIGHT_FOR_OVERFLOW",true);//高度溢出缩放
			// LODOP.SET_SHOW_MODE("HIDE_PAPER_BOARD",true);//隐藏走纸板
			LODOP.SET_PREVIEW_WINDOW(0, 3, 0, 0, 0, ""); //隐藏工具条，设置适高显示
			LODOP.SET_SHOW_MODE("PREVIEW_IN_BROWSE", true); //预览界面内嵌到页面内
			LODOP.PREVIEW();
		}

		LODOP.On_Return = function () {
			callback && callback({ status: true });
		};
	} catch {
		if (callback) {
			callback({ status: false });
		} else {
			Modal.info({ content: "打印出错了" });
		}
	}
}

export function printCard1({ type = 1, data = {}, goods = obj, index }, callback) {
	const { templateName, totalWidth, totalHeight, templateValue } = data;
	const arr = ["type", "id", "props", "value", "fontSize"];
	// const arr = ['left', 'top', 'width', 'height']
	try {
		// const html = `<table border=0 cellSpacing=0 cellPadding=0  width="32px" height="100%"><tr><td>1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设1.并不是程序设置了纸张大小就一定生效,需要选择真实打印机然后预览下方查看,才能确认纸张和设置纸张一致。 在预览里选择真实打印机,下方状态栏可以看到纸张,有的打印机纸张可能不生效,排查一下是否和设置的纸张一致。</td></tr></table>`

		LODOP = getLodop();
		LODOP.PRINT_INIT(templateName);
		// LODOP.SET_PRINT_PAGESIZE(0, 760, 1300, "");
		LODOP.SET_PRINT_PAGESIZE(0, totalWidth * 10, totalHeight * 10, "");
		templateValue &&
			JSON.parse(templateValue).map(item => {
				const { top, left, width, height } = item;
				if (top < totalHeight * 3.8) {
					let html = `<table border=0 cellSpacing=0 cellPadding=0 width=${totalWidth}mm height="100%" style="position:relative;"><tr><td>`;
					if (item.type == "text") {
						let style = "position:absolute;overflow:hidden;",
							str = "";
						item.props.map(prop => {
							if (goods[prop]) {
								str += `${goodsInfoMap[prop]}：${goods[prop]};`;
							}
						});
						Object.keys(item).map(child => {
							if (!arr.includes(child)) {
								style += `${child}:${item[child]}px;`;
							}
						});
						html += `<div style=${style}>${str}</div>`;
						html += `</td></tr></table>`;
						LODOP.ADD_PRINT_TABLE(0, 0, "100%", "100%", html);
						LODOP.SET_PRINT_STYLEA(0, "fontSize", item["fontSize"]);
					} else if (item.type == "customtext") {
						let style = "position:absolute;overflow:hidden;";
						Object.keys(item).map(child => {
							if (!arr.includes(child)) {
								style += `${child}:${item[child]}px;`;
							}
						});
						html += `<div style=${style}>${item.value}</div>`;
						html += `</td></tr></table>`;
						LODOP.ADD_PRINT_TABLE(0, 0, "100%", "100%", html);
						LODOP.SET_PRINT_STYLEA(0, "fontSize", item["fontSize"]);
					} else if (item.type == "barcode" && goods["goodsId"]) {
						LODOP.ADD_PRINT_BARCODE(top, left, width, height, "128Auto", goods["goodsId"]);
					} else if (item.type == "qrcode") {
						LODOP.ADD_PRINT_BARCODE(top, left, width, height, "QRCode", item.value);
					} else if (item.type == "picture") {
						LODOP.ADD_PRINT_IMAGE(
							top,
							left,
							width,
							height,
							`<img border='0' src=${item.value} width=${width} height=${height} />`
						);
					}
				}
			});

		LODOP.PRINT();
		// LODOP.PREVIEW();
		LODOP.On_Return = function () {
			callback && callback({ status: true });
		};
	} catch {
		console.log("chucuo");
	}
}

//统一format数据推送打印
export const formatAndPushPrint = (list = {}, callback) => {
	const {
		platform,
		printData,
		orderSn,
		note,
		expressId,
		fontItem,
		customData = {},
		tokenStr,
		flag,
		name,
		num = 1,
		len = 1
	} = list; //注意后四个是format进入的字段，flag, name不可或缺
	if (platform == 0) {
		//清单打印
		printCheckList(
			JSON.parse(printData),
			res => {
				callback && callback(res);
			},
			name
		);
		return;
	}

	if (platform == 2 || platform == 28) {
		//拼多多
		let data;
		if (flag == "spd") {
			const customUrlSpecial = "http://qiniutest.zhaojiafang.com/pinduoduo/3000131/1639031132078",
				customUrlDefault1 =
					"https://pos-file.pinduoduo.com/express-common-no-cache/common/xmltemplate/printtemplate_079e27627da94411a6e976f44eb39f07.xml",
				customUrlDefault2 =
					"https://pos-file.pinduoduo.com/express-common-no-cache/common/xmltemplate/printtemplate_221a9f43d6894604a1fea5cfc4eb17ed.xml";
			data = {
				ERPId: 303379400,
				cmd: "print",
				requestID: orderSn + Date.now(),
				task: {
					documents: [
						{
							contents: [
								JSON.parse(printData),
								{
									data: {
										note,
										key1: note,
										zjf: "ZJF    二区陈剑",
										waterdata: {
											text: ""
										},
										width: 560
									},
									templateURL: expressId == 898 ? customUrlSpecial : fontItem == 7 ? customUrlDefault1 : customUrlDefault2
								}
							],
							documentID: orderSn
						}
					],
					notifyType: ["print"],
					preview: false,
					previewType: "image",
					printer: name,
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len
				},
				version: "1.0"
			};
		} else {
			data = {
				ERPId: 303379400,
				cmd: "print",
				requestID: orderSn + Date.now(),
				task: {
					documents: [
						{
							contents: [JSON.parse(printData), { ...customData }],
							documentID: orderSn
						}
					],
					notifyType: ["print"],
					preview: false,
					previewType: "image",
					printer: name,
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len
				},
				version: "1.0"
			};
		}
		print(1, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 6 || platform == 29) {
		//京东
		let data;
		const printObj = JSON.parse(printData);
		if (flag == "spd") {
			const customUrlSpecial = "http://qiniutest.zhaojiafang.com/jingdong/3000131/1639030411698",
				customUrlDefault =
					"https://storage.360buyimg.com/jdl-template/custom-6c9d2ab0-d337-47a3-86ea-4a4b29f33b04.1623382664458.txt";
			data = {
				orderType: "print",
				parameters: {
					printName: name,
					addData: printObj.addData,
					tempUrl: printObj.tempUrl,
					customTempUrl: expressId == 898 ? customUrlSpecial : customUrlDefault,
					customData: [
						{
							customInfo: note,
							key1: note,
							tradeId: orderSn + Date.now()
						}
					],
					printData: [printObj.data]
				}
			};
		} else {
			data = {
				orderType: "print",
				dataType: printObj.dataType,
				parameters: {
					printName: name,
					addData: printObj.addData,
					tempUrl: printObj.tempUrl,
					customTempUrl: customData.templateURL,
					customData: [customData.data],
					printData: [printObj.data]
				}
			};
		}
		print(6, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 7) {
		//唯品会
		printVipShop(
			printData,
			res => {
				callback && callback(res);
			},
			name
		);
		return;
	}

	if (platform == 32) {
		//得物
		printDewu(
			{
				index: printData.name,
				logisticsNo: printData.logisticsNo
			},
			res => {
				callback && callback(res);
			},
			name
		);
		return;
	}

	if (platform == 8) {
		//唯品会
		const printObj = JSON.parse(printData);
		const data = {
			actionType: "PRINT",
			traceId: +new Date(),
			storeId: printObj.storeId,
			printerName: name,
			printParamDTO: {
				templateUrl: printObj.tempUrl,
				printDatas: [printObj],
				customData: customData
			}
		};
		print(8, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 14) {
		//快手
		let data;
		const printObj = JSON.parse(printData);
		if (flag == "spd") {
			const customUrlDefault1 = "https://s1-11586.kwimgs.com/kos/nlav11586/template/custom/EBCT-EBCTO6417.xml",
				customUrlDefault2 = "https://s2-11586.kwimgs.com/kos/nlav11586/template/custom/EBCT-EBCTO6420.xml";
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: false,
					printer: name,
					previewType: "pdf",
					firstDocumentNumber: num,
					totalDocumentCount: len,
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									addData: printObj.addData,
									encryptedData: printObj.printData,
									signature: printObj.signature,
									key: printObj.key,
									templateURL: printObj.templateURL,
									ver: "waybill_print_secret_version_1"
								},
								{
									customData: { key1: note },
									templateURL: fontItem == 7 ? customUrlDefault1 : customUrlDefault2
								}
							]
						}
					]
				}
			};
		} else {
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: false,
					printer: name,
					previewType: "pdf",
					firstDocumentNumber: num,
					totalDocumentCount: len,
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									addData: printObj.addData,
									encryptedData: printObj.printData,
									signature: printObj.signature,
									key: printObj.key,
									templateURL: printObj.templateURL,
									ver: "waybill_print_secret_version_1"
								},
								{
									customData: list?.customData?.data,
									templateURL: list?.customData?.templateURL
								}
							]
						}
					]
				}
			};
		}
		print(14, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 15) {
		//抖音
		let data;
		const printObj = JSON.parse(printData);
		if (flag == "spd") {
			const customUrlSpecial =
				"https://cloudprint.douyinec.com/api/logistics/davinci/template/xml/NI2qmwRL0SBAyVy8Vl1LuxbC4JAgsVpSPxcSlty2GNMHgC5cCmkMGeHiuz2MzkMqbHyTBFa6QhG8lrQW38aTtLOdWGMwoEeEv92U",
				customUrlDefault =
					"https://cloudprint.douyinec.com/api/logistics/davinci/template/xml/zvZ4w7EVV7v8YfmbeWxsJkCrb3waXZuZnwydbTcKy6nvkf84bSHKTzK7ZhYif4ouCSF9l7rbEItjdUrRazgWWAoXlYgcLUabSCvf";
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0.1.8",
				task: {
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len,
					preview: false,
					printer: name,
					previewType: "pdf",
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									signature: printObj.sign,
									templateURL: printObj.templateURL,
									params: tokenStr,
									encryptedData: printObj.print_data,
									addData: printObj.addData
								},
								{
									note,
									templateURL: expressId == 898 ? customUrlSpecial : customUrlDefault
								}
							]
						}
					]
				}
			};
		} else {
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0.1.8",
				task: {
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len,
					preview: false,
					printer: name,
					previewType: "pdf",
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									signature: printObj.sign,
									templateURL: printObj.templateURL,
									params: tokenStr,
									encryptedData: printObj.print_data,
									addData: printObj.addData
								},
								{ ...customData }
							]
						}
					]
				}
			};
		}
		print(15, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 25) {
		//微信视频号
		const printObj = JSON.parse(printData);
		const data = {
			command: "print",
			version: "2.0",
			requestID: orderSn + Date.now(),
			printer: name,
			taskList: [
				{
					taskID: orderSn + Date.now(),
					printInfo: printObj.printData,
					printNum: {
						curNum: num,
						sumNum: len
					},
					customInfo: { templateUrl: list?.customData?.templateURL, data: list?.customData?.data },
					extendData: { ...printObj.addData }
				}
			]
		};
		print(25, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 33) {
		//得物
		const printObj = JSON.parse(printData);
		const data = {
			cmd: "print",
			version: "2.2.1",
			requestID: orderSn + Date.now(),
			task: {
				isvName: "isvName", // ISV 名称
				taskID: orderSn + Date.now(),
				printer: name,
				firstDocumentNumber: num,
				totalDocumentCount: len,
				documents: [
					{
						printData: { ...printObj, customContent: undefined },
						customContent: printObj.customContent
					}
				]
			}
		};
		print(33, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (platform == 40) {
		//小红书
		const data = {
			cmd: "print",
			requestID: orderSn + Date.now(),
			version: "1.0",
			task: {
				taskID: orderSn + Date.now(),
				preview: false,
				printer: name,
				previewType: "pdf",
				firstDocumentNumber: num,
				totalDocumentCount: len,
				documents: [
					{
						documentID: orderSn,
						contents: [JSON.parse(printData), { ...customData }]
					}
				]
			}
		};
		print(40, data, res => {
			callback && callback(res);
		});
		return;
	}

	if (true) {
		//其余均走菜鸟
		let data;
		if (platform == 5) {
			//顺丰
			data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: false,
					printer: name,
					previewType: "pdf",
					firstDocumentNumber: num,
					totalDocumentCount: len,
					documents: [
						{
							documentID: orderSn,
							contents: [JSON.parse(printData)]
						}
					]
				}
			};
		} else {
			if (flag == "spd") {
				const customUrlSpecial = "http://qiniutest.zhaojiafang.com/taobao/3000131/1639030368752",
					customUrlDefault1 = "http://cloudprint.cainiao.com/template/customArea/11524019/30",
					customUrlDefault2 = "http://cloudprint.cainiao.com/template/customArea/12037752/19";
				data = {
					cmd: "print",
					requestID: orderSn + Date.now(),
					version: "1.0",
					task: {
						taskID: orderSn + Date.now(),
						preview: false,
						printer: name,
						previewType: "pdf",
						firstDocumentNumber: num,
						totalDocumentCount: len,
						documents: [
							{
								documentID: orderSn,
								contents: [
									JSON.parse(printData),
									{
										data: {
											value: note,
											key1: note,
											zjf: "ZJF    二区陈剑"
										},
										templateURL: expressId == 898 ? customUrlSpecial : fontItem == 7 ? customUrlDefault1 : customUrlDefault2
									}
								]
							}
						]
					}
				};
			} else {
				data = {
					cmd: "print",
					requestID: orderSn + Date.now(),
					version: "1.0",
					task: {
						taskID: orderSn + Date.now(),
						preview: false,
						printer: name,
						previewType: "pdf",
						firstDocumentNumber: num,
						totalDocumentCount: len,
						documents: [
							{
								documentID: orderSn,
								contents: [JSON.parse(printData), { ...customData }]
							}
						]
					}
				};
			}
		}
		print(2, data, res => {
			callback && callback(res);
		});
		return;
	}
};

// const printData ="{\"print_data\":\"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\",\"ecStoreId\":28888,\"sign\":\"LdUVsnCFnFGsRwQOUNI40i1Jv2G+d5PeONQ8A4yOWGgOVQSj5wqasFbfTFu61u+J6El7fbYRlL2mACBWiZ0OtF9BnYDk9AoF0HaXzUtE/sQB6Vht6wC1WSB37fD/ZzpxN9brpLvEUxLGMApoCXh36LgNUcdSuKb/Knaz1b5dXGOIgYQ9gZ1qAqk2xVjkJkZI/dUz8L5foBmSVmv9MwCKPwPb1uG9/wPQRo0HKy5l6xjhkNrBpj0GNKOM4TgntvzIxcF6zvFWXbB61hG1y61b+yFcEB0PVE5XpuchtUK9Sj1i9SlLLqJV0Z8rhLeV2Yw+SbgV2dgxy4M8E2gyEqhh1A==\",\"addData\":{\"sender\":{\"address\":\"湖北十堰市丹江口市武当山总裁办\",\"name\":\"张三丰\",\"mobile\":\"18888888888\"}},\"track_no\":\"990201842566475\",\"order_id\":\"M20221031150068104768|55984562|180|54\",\"templateURL\":\"https://sf3-ttcdn-tos.pstatp.com/obj/logistics-davinci/template/template_fengwang76.xml\"}"

// formatAndPushPrint({printData, platform: 15, orderSn: '3425634643654234234', tokenStr: '62edeee6-4fc4-474e-adaf-6eed0b7630e8', name: '导出为WPS PDF'})

// 打印备货单
export const printStockList = (data, callback) => {
	try {
		const { index, spuList = [], storeName, shopArea, userName, storeGoodsNum } = data;
		let html = `<table border="1" cellSpacing="0" cellPadding="0" width="100%" height="${spuList.length >= 14 ? "100%" : "auto"}" style="border-collapse:collapse;">
		<caption>备货汇总</caption>
		<thead>
		<tr style="height:40px; width: 100%">
		<td colspan="7">供应商：${storeName}&nbsp;&nbsp;&nbsp;&nbsp;区域编码：${shopArea}&nbsp;&nbsp;&nbsp;&nbsp;用户：${userName}&nbsp;&nbsp;&nbsp;&nbsp;总数：${storeGoodsNum}</td>
		</tr>
		<tr style="height:40px; width: 100%">
		<td style="width: 8%">序号</td>
		<td style="width: 8%">图片</td>
		<td style="width: 10%">款式编码</td>
		<td style="width: 45%">
		<div style="display:flex; height: 40px; line-height: 40px;">
        <span style="flex: 1; padding:0 6px">规格</span>
        <span style="width:42px; padding:0 6px; border-left:1px solid #333; border-right:1px solid #333;">数量</span>
        <span style="width:110px; padding:0 6px;">商品编码</span>
      </div>
		</td>
		<td style="width: 6%">总数量</td>
		<td style="width: 16%">商品名称</td>
		<td style="width: 6%;">单价</td>
		</tr></thead><tbody>`;
		let tbodyStr = spuList.map((item, index) => {
			const goodsStr = item.goodsList.map(child => {
				return `<div style="display:flex; justifyContent:space-arround;">
				<div style="flex: 1; padding:0 6px">${child.goodsSpec}</div>
				<div style="width:42px; padding:0 6px;" >x ${child.goodsNum}</div>
				<div style="width:110px; padding:0 6px; word-break: break-all;">${child.goodsCode}</div>
			</div>`;
			});

			const goodsPriceStr = item.goodsList.map(child => {
				return `<div>${formatAmount(child.goodsPrice)}</div>`;
			});

			const goodsImageStr =
				item.image.includes("https") || item.image.includes("http")
					? item.image
					: `https://imgniu.zhaojiafang.com/store/goods/${item?.goodsList?.[0]?.storeId}/${item.image}`;

			return `<tr style="height:60px; width: 100%">
		  <td style="width: 8%">${index + 1}</td>
			<td style="width: 8%"><img style="width: 48px" src="${goodsImageStr}" /></td>
			<td style="width: 10%">${item.styleCode}</td>
		  <td style="width: 45%">${goodsStr.join("")}</td>
		  <td style="width: 6%; text-align:center">x ${item.goodsNum}</td>
			<td style="width: 16%; padding:0 6px;">${item.goodsName}</td>
			<td style="width: 6%; text-align:center;">${goodsPriceStr.join("")}</td>
			</tr>`;
		});
		html = html + tbodyStr.join("");
		+"</tbody></table>";

		var LODOP = getLodop();
		LODOP.PRINT_INIT("备货汇总");
		if (index || index == 0) {
			// console.log('index',index)
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
		}

		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
		LODOP.ADD_PRINT_HTM("2%", "1%", "96%", "98%", html);
		LODOP.PRINT();
		//  LODOP.PRINT_DESIGN(); //设计+
		LODOP.On_Return = function (TaskID, value) {
			callback &&
				callback({
					success: true,
					status: 0
				});
		};
	} catch (error) {
		console.log(error, "sdf");
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
};

//打印条码（无订单退货）
export function printBarcode(obj, callback) {
	const { printer, headCode = "", storeName = "", refundAmount = "", storeAddress = "", refundAccount = "", note = "" } = obj;
	try {
		LODOP = getLodop();
		LODOP.PRINT_INIT("打印商品条码");
		if (printer || printer == 0) {
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", printer);
		}
		LODOP.SET_PRINT_PAGESIZE(0, 700, 500, "");
		LODOP.ADD_PRINT_TEXT(5, 183, 57, 21, refundAccount);
		LODOP.ADD_PRINT_TEXT(41, 18, 100, 20, storeName);
		LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
		LODOP.ADD_PRINT_TEXT(41, 128, 100, 20, `价格: ${refundAmount}`);
		LODOP.ADD_PRINT_TEXT(54, 18, 210, 20, storeAddress);
		LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
		LODOP.ADD_PRINT_BARCODE(2, 23, 167, 39, "128Auto", headCode);
		// LODOP.ADD_PRINT_TEXT(73,13,210,20,`备注内容：${note}`);
		LODOP.PRINT();
		// LODOP.PRINT_DESIGN();
		LODOP.On_Return = function () {
			callback &&
				callback({
					success: true,
					status: 1
				});
		};
	} catch (error) {
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
}

export const kuaiXiaoPrintFunc = async (list = {}, callback) => {
	console.log(list, 'ddd3:::::::::::::::::::::::::::::::::::333d')
	try {
		const {
			platform,
			printData,
			orderSn,
			logPage,
			printTaskId,
			note,
			expressId,
			fontItem,
			sendInfo = {},
			customData = {},
			sendTemplateURL,
			tokenStr,
			flag,
			printer: name,
			num = 1,
			len = 1,
			customTemplateUrl
		} = list; //注意后四个是format进入的字段，flag, name不可或缺

		const printObj = JSON.parse(printData),
		
			addData = {
				sender: {
					name: sendInfo.name,
					mobile: sendInfo.mobile,
					address: Object.values(sendInfo.address).join("")
				}
			},
			pddAddData = {
				addData: {
					sender: {
						...sendInfo
					}
				}
			},
			videoAddData = {
				sender: {
					address: {
						provinceName: sendInfo.address?.province,
						cityName: sendInfo.address?.city,
						countyName: sendInfo.address?.district,
						detailInfo: sendInfo.address?.detail
					},
					userName: sendInfo.name,
					telNumber: sendInfo.mobile
				}
			},
			specAddData = {
				sender: {
					address: sendInfo.address,
					name: sendInfo.name,
					mobile: sendInfo.mobile,
				}
			},
			senderInfo = {
				address: {
					cityName: sendInfo?.address?.city,
					countryCode: "CHN",
					detailAddress: sendInfo?.address?.detail,
					districtName: sendInfo?.address?.district,
					provinceName: sendInfo?.address?.province,
					streetName: sendInfo?.address?.street
				},
				contact: {
					mobile: sendInfo.mobile,
					name: sendInfo.name
				}
			};

		if (platform == 2 || platform == 28) {
			const data = {
				ERPId: 303379400,
				cmd: "print",
				requestID: orderSn + Date.now(),
				task: {
					documents: [
						{
							contents: [
								{
									...pddAddData,
									...printObj,
								},
								{
									data: customData,
									templateURL: customTemplateUrl
								}
							],
							documentID: orderSn
						}
					],
					notifyType: ["print"],
					preview: false,
					previewType: "image",
					printer: name,
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len
				},
				version: "1.0"
			};
			console.log(data, customData, 'custom')
			print(1, data, res => {
				callback && callback({ ...res, logPage, printTaskId, orderSn });
			});
			return;
		}

		if (platform == 6) {
			const data = {
				orderType: "print",
				dataType: printObj.dataType,
				parameters: {
					addData,
					printName: name,
					tempUrl: printObj.tempUrl,
					customTempUrl: customTemplateUrl,
					customData: [customData],
					printData: [printObj.data]
				}
			};
			print(6, data, res => {
				callback && callback({ ...res, logPage, printTaskId, orderSn });
			});
			return;
		}

		if (platform == 14) {
			const data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0",
				task: {
					taskID: orderSn + Date.now(),
					preview: false,
					printer: name,
					previewType: "pdf",
					firstDocumentNumber: num,
					totalDocumentCount: len,
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									addData: { senderInfo },
									encryptedData: printObj.printData,
									signature: printObj.signature,
									key: printObj.key,
									templateURL: printObj.templateURL,
									ver: "waybill_print_secret_version_1"
								},
								{
									customData,
									templateURL: customTemplateUrl,
								}
							]
						}
					]
				}
			};

			print(14, data, res => {
				callback && callback({ ...res, logPage, printTaskId, orderSn });
			});
			return;
		}

		if (platform == 15) {
			const { data: tokenStr } = (await queryDouYinPrintParam({ orderCode: orderSn })) || {};
			const data = {
				cmd: "print",
				requestID: orderSn + Date.now(),
				version: "1.0.1.8",
				task: {
					taskID: orderSn + Date.now(),
					firstDocumentNumber: num,
					totalDocumentCount: len,
					preview: false,
					printer: name,
					previewType: "pdf",
					documents: [
						{
							documentID: orderSn,
							contents: [
								{
									// customData,
									// senderInfo,
									addData: { senderInfo },
									signature: printObj.sign,
									templateURL: printObj.templateURL,
									params: tokenStr,
									encryptedData: printObj.print_data
								},
								{
									data: customData,
									templateURL: customTemplateUrl
								}
							]
						}
					]
				}
			};
			print(15, data, res => {
				callback && callback({ ...res, logPage, printTaskId, orderSn });
			});
			return;
		}

		if(platform == 25){//微信视频号
			const printObj = JSON.parse(printData);
			const data = {
				command: 'print',
				version: '2.0',
				requestID: orderSn + Date.now(),
				printer: name,
				taskList: [{
					taskID: orderSn + Date.now(),
					printInfo: printObj.printData,
					printNum: {
						curNum: num,
						sumNum: len
					},
					customInfo: { 
						templateUrl: customTemplateUrl, 
						data: list?.customData 
					},
					extendData: { ...videoAddData }
				}]
			}
			print(25, data, res => {
				callback && callback({ ...res, logPage, printTaskId, orderSn });
			})
			return
		}

		const data = {
			cmd: "print",
			requestID: orderSn + Date.now(),
			version: "1.0",
			task: {
				taskID: orderSn + Date.now(),
				preview: false,
				printer: name,
				previewType: "pdf",
				firstDocumentNumber: num,
				totalDocumentCount: len,
				documents: [
					{
						documentID: orderSn,
						contents: [
							{
								...printObj,
								addData: specAddData,
								// ...customData
							},
							{
								data: customData,
								templateURL: customTemplateUrl
							}
						]
					}
				]
			}
		};

		print(2, data, res => {
			callback && callback({ ...res, logPage, printTaskId, orderSn });
		});
	} catch (err) {
		console.log(err, 'err')
		//防止解析数据js报错
		callback({ status: false });
	}
};

// 打印快销备货单
export const printKxStockList = (data, callback) => {
	try {
		const { index, columns, accountNo, supplierArea, supplierName, supplierSkuQuantity, supplierSkuTotalPrice, goodsList } = data;
		console.log(data, 'data')
		console.log(columns, 'columnscolumnscolumnscolumns')
		var LODOP = getLodop();
		LODOP.PRINT_INIT("快销备货汇总");
		if (index || index == 0) {
			console.log('index', index)
			LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER", index);
			LODOP.SET_PRINTER_INDEX(index);
		}
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
		let html = `
		<table border="1" cellSpacing="0" cellPadding="0" width="100%" height="auto" style="border-collapse:collapse;">
			<caption>快销备货汇总</caption>
			<thead>
				<tr style="height:40px;width:100%">
				<td colspan="${columns.length}" style="padding:0 4px;background:#F7F8FC;">供应商：${supplierName}&nbsp;&nbsp;&nbsp;&nbsp;区域编码：${supplierArea}&nbsp;&nbsp;&nbsp;&nbsp;用户：${accountNo}&nbsp;&nbsp;&nbsp;&nbsp;总数：${supplierSkuQuantity}&nbsp;&nbsp;&nbsp;&nbsp;总价：${supplierSkuTotalPrice}</td>
				</tr>
				<tr style="height:40px;width:100%">
		`
		const totalWidth = columns.reduce((pre, next) => pre + next.width, 0);
		columns.map(v => {
			const width = parseInt(v.width / totalWidth * 100);
			html += `<td style="width:${width}%;padding:0 4px;">${v.title}</td>`;
		})
		html += `</tr></thead><tbody>`;
		goodsList.map((v, index) => {
			const length = v.pickingGoodsSummarySkuVOList.length;
			v.pickingGoodsSummarySkuVOList.map((item, index1) => {
				html += '<tr style="width:100%">'
				columns.map((k) => {
					const width = parseInt(k.width / totalWidth * 100);
					if (k.code == 'dataIndex') {
						if(index1 == 0) {
							html += `<td rowspan="${length}" style="width:${width}%;padding:2px 4px;">${index + 1}</td>`
						} else {
							html += `<td style="display:none;"></td>`
						}
					} else if (k.code == 'skuImage') {
						if(index1 == 0) {
							html += `<td rowspan="${length}" style="width:${width}%;padding:2px 4px;"><img style="width:48px" src="${v[k.code]}" /></td>`
						} else {
							html += `<td style="display:none;"></td>`
						}
					} else if (['skuCode', 'colorSpecifications', 'codeQuantity', 'skuPrice'].includes(k.code)) {
						html += `<td style="width:${width}%;padding:2px 4px;">${item[k.code]}</td>`
					} else {
						if(index1 == 0) {
							html += `<td rowspan="${length}" style="width:${width}%;padding:2px 4px;">${v[k.code]}</td>`
						} else {
							html += `<td style="display:none;"></td>`
						}
					}
				})
				html += '</tr>'
			})
		})
		html += '</tbody></table>'
		console.log(html, 'html')
		LODOP.ADD_PRINT_HTM("2%", "1%", "96%", "98%", html);
		LODOP.PRINT();
		//  LODOP.PRINT_DESIGN(); //设计+
		LODOP.On_Return = function (TaskID, value) {
			callback &&
				callback({
					success: true,
					status: 0
				});
		};
	} catch (error) {
		console.log(error, "sdf");
		callback &&
			callback({
				success: false,
				status: 1
			});
	}
};